<?php
	session_start();
	include 'base_config.php';
	
	if (isset($_REQUEST['sessionid'])) {
		$session_id = $_REQUEST['sessionid'];
		$session_id =  mysql_real_escape_string($session_id);
		
		if ($session_id === session_id()) {			
			header($contentType_Javascript);
			header($cache);
			header($pragma);
			
			$arr = array();
			//Execute the query
			$sql = "SELECT `idBookmark`, `bookmarkName`, `bookmarkURL`, `bookmarkDescription`, `bookmarkImagePath`, `active`, `bookmarkCount` FROM `bookmark`";	
			$rs = mysql_query($sql);
		   
			// Add the rows to the array
			while($obj = mysql_fetch_object($rs)) {			
				if ($obj->bookmarkImagePath == null) {
					$obj->bookmarkImagePath = "null";
				}
				$obj->bookmarkDescription = utf8_encode($obj->bookmarkDescription);
				if  ($obj->bookmarkDescription == null) {
					$obj->bookmarkDescription = "null";
				}
				$arr[] = $obj;
			}
	
			echo '{"bookmarks":' . json_encode($arr).'}';
			mysql_close($connect);
		} else {
			echo utf8_encode("NoUserFound");
			session_unset();
			session_destroy();
		}
	}